# -*- coding: utf-8 -*-
from fixture import user
from api.base_api.base_api import BaseApi
from api.base_api.register import RegisterApi

class LoginApi(BaseApi):
    login_url = "http://192.168.1.141:8001/login"


    def login(self, mobile, password, captcha_code=None):
        # 登录
        captcha_hash = RegisterApi().get_user_captcha_hash()
        if captcha_code:
            payload = {
                "mobile": mobile,
                "captcha_hash": captcha_hash,
                "captcha_code": captcha_code,
                "password": password
            }
        else:
            get_captcha_code = user.get_response(captcha_hash)
            payload = {
                "mobile": mobile,
                "captcha_hash": captcha_hash,
                "captcha_code": get_captcha_code,
                "password": password
            }
        response = self.post(self.login_url, payload)
        return response
